#include <iostream>
using namespace std;

#include "Force.h"

Force::Force(int iAr, int iGr, int ar, int gr, float xp, float sp, int turns, float fp, int cm) : 
iAeroRating(iAr), iGroundRating(iGr), aeroRating(ar), groundRating(gr), exp(xp), 
supplyPts(sp), numTurnsWOSupply(turns), fatiguePts(fp), combatMod(cm) {
	setSupplyNeed(); 
	setRating();
	setLeaderRating();
}

int Force::getiAeroRating() { return iAeroRating; }
int Force::getiGroundRating() { return iGroundRating; }
int Force::getAeroRating() { return aeroRating; }
int Force::getGroundRating() { return groundRating; }
int Force::getLeaderRating() { return leaderRating; }
float Force::getExp() { return exp; }
int Force::getRating() { return rating; }
int Force::getSupplyNeed() { return supplyNeed; }
float Force::getSupplyPts() { return supplyPts; }
int Force::getNumTurnsWOSupply() { return numTurnsWOSupply; }
float Force::getFatiguePts() { return fatiguePts; }
int Force::getCombatMod() { return combatMod; }

void Force::setiAeroRating(int ar) { iAeroRating = ar; }
void Force::setiGroundRating(int gr) { iGroundRating = gr; }
void Force::setAeroRating(int ar) { aeroRating = ar; }
void Force::setGroundRating(int gr) { groundRating = gr; }
// Calculate intrinsic Leader Rating based on experience level of force
void Force::setLeaderRating() { 
	if(rating == 1) leaderRating = 2;
	if(rating == 2) leaderRating = 3;
	if(rating == 3) leaderRating = 4;
	if(rating == 4) leaderRating = 5;
}
void Force::setExp(float xp) { exp = xp; }
// Set experience level of force based on experience points of force
void Force::setRating() {
	int xp = (int)exp;
	if( xp>0 && xp<6 ) rating = 1;
	else if( xp>5 && xp<16 ) rating = 2;
	else if( xp>15 && xp<31 ) rating = 3;
	else if( xp>30 ) rating = 4;
}
// Calculate supply need of force based on sum of Aero Rating and Ground Rating
void Force::setSupplyNeed() { 
		if( (aeroRating + groundRating) % 1000 == 0 ) supplyNeed = (aeroRating + groundRating) / 1000;
		else supplyNeed = (aeroRating + groundRating) / 1000 + 1;
}
void Force::setSupplyPts(float sp) { supplyPts = sp; }
void Force::setNumTurnsWOSupply(int turns) { numTurnsWOSupply = turns; }
void Force::setFatiguePts(float fp) { fatiguePts = fp; }
void Force::setCombatMod(int cm) { combatMod = cm; }

// Return true if Surrender Level has been exceeded based on initial and current ratings and rating
bool Force::checkSurrenderLimit() {

	int iniRating = iAeroRating + iGroundRating; 
	int curRating = aeroRating + groundRating;

	switch(rating) {
	
		case 1:	if(curRating / (float)iniRating < 0.40) return true;

		case 2: if(curRating / (float)iniRating < 0.30) return true;

		case 3: if(curRating / (float)iniRating < 0.20) return true;

		case 4: if(curRating / (float)iniRating < 0.10) return true;

	}
	return false;

}